package com.pine.manager.pineframework.trigger;

import com.pine.common.beans.pineframework.request.*;
import com.pine.common.beans.pineframework.response.SysUserLoginResponse;
import com.pine.common.beans.request.BatchIdRequest;
import com.pine.common.beans.response.DeleteResponse;
import com.pine.common.trigger.TriggerContext;
import com.pine.common.trigger.TriggerUtil;
import com.pine.manager.core.TriggerTypeEnum;

/**
 * <p>
 * 用户 触发器管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-08-13
 */
public class SysUserTriggerManager {

    /**
     * 用户登录
     *
     * @param request 请求体
     * @return 响应体
     */
    public static SysUserLoginResponse login(SysUserLoginRequest request) {
        TriggerContext<SysUserLoginRequest> triggerContext = new TriggerContext<>(TriggerTypeEnum.SYS_USER_LOGIN, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }

    /**
     * 用户新增或修改
     *
     * @param request 请求体
     * @return 响应体
     */
    public static Boolean saveOrUpdate(SysUserSaveOrUpdateRequest request) {
        TriggerContext<SysUserSaveOrUpdateRequest> triggerContext = new TriggerContext<>(TriggerTypeEnum.SYS_USER_SAVE_OR_UPDATE, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }

    /**
     * 删除用户
     *
     * @param request 请求体
     * @return 响应体
     */
    public static DeleteResponse delete(BatchIdRequest<Long> request) {
        TriggerContext<BatchIdRequest<Long>> triggerContext = new TriggerContext<>(TriggerTypeEnum.SYS_USER_DELETE, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }

    /**
     * 重置密码
     *
     * @param request 请求体
     * @return 响应体
     */
    public static Boolean resetPassword(SysUserResetPasswordRequest request) {
        TriggerContext<SysUserResetPasswordRequest> triggerContext = new TriggerContext<>(TriggerTypeEnum.SYS_USER_RESET_PASSWORD, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }

    /**
     * 修改状态
     *
     * @param request 请求体
     * @return 响应体
     */
    public static Boolean updateStatus(SysUserUpdateStatusRequest request) {
        TriggerContext<SysUserUpdateStatusRequest> triggerContext = new TriggerContext<>(TriggerTypeEnum.SYS_USER_UPDATE_STATUS, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }

    /**
     * 分配角色
     *
     * @param request 请求体
     * @return 响应体
     */
    public static Boolean assignRole(SysUserAssignRoleRequest request) {
        TriggerContext<SysUserAssignRoleRequest> triggerContext = new TriggerContext<>(TriggerTypeEnum.SYS_USER_ASSIGN_ROLE, request);
        return TriggerUtil.triggerWithLock(triggerContext);
    }
}
